/**
 * 
 */
package co.gov.medellin.sdep.sisdep.operativa.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.operativa.exception.CharlaPAgendaException;
import co.gov.medellin.sdep.sisdep.operativa.exception.CharlaPAgendaRuntimeException;
import co.gov.medellin.sdep.sisdep.operativa.exception.descriptor.CharlaPAgendaMessageDescriptor;
import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.CharlaPAgenda;
import co.gov.medellin.sdep.sisdep.model.dao.impl.ICharlaPAgendaDAOT;

/**
 * @author Usuario
 *
 */
public class CharlaPAgendaServiceImpl extends BaseService implements ICharlaPAgendaService {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private ICharlaPAgendaDAOT charlaPAgendaDAO;

	/**
	 * 
	 */
	public CharlaPAgendaServiceImpl() {
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(CharlaPAgenda charlaPAgenda) throws CharlaPAgendaException {
		try{
			charlaPAgenda.setUsuarioCrea(getPrincipalUser());
			charlaPAgenda.setFechaCrea(new Date());
			getCharlaPAgendaDAO().insert(charlaPAgenda);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new CharlaPAgendaException(new CharlaPAgendaMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new CharlaPAgendaException(new CharlaPAgendaMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(CharlaPAgenda charlaPAgenda) throws CharlaPAgendaException {
		try{
			charlaPAgenda.setUsuarioModifica(getPrincipalUser());
			charlaPAgenda.setFechaModifica(new Date());
			getCharlaPAgendaDAO().update(charlaPAgenda);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new CharlaPAgendaRuntimeException(new CharlaPAgendaMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new CharlaPAgendaRuntimeException(new CharlaPAgendaMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(CharlaPAgenda charlaPAgenda) throws CharlaPAgendaException {
		try {
			charlaPAgenda.setUsuarioModifica(getPrincipalUser());
			charlaPAgenda.setFechaModifica(new Date());
			getCharlaPAgendaDAO().delete(charlaPAgenda);
		}catch (Exception e) {
			Object [] infoError = {
			};
			throw new CharlaPAgendaRuntimeException(new CharlaPAgendaMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, CharlaPAgenda charlaPAgenda) throws CharlaPAgendaException {
		try{
			//return getCharlaPAgendaDAO().getAllCharlaPAgendaPaginated(start, max, criteria);
			return getCharlaPAgendaDAO().load();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new CharlaPAgendaRuntimeException(new CharlaPAgendaMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	/**
	 * 
	 */
	public final CharlaPAgenda get(long id) throws CharlaPAgendaException {
		try{
			return getCharlaPAgendaDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new CharlaPAgendaRuntimeException(new CharlaPAgendaMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public ICharlaPAgendaDAOT getCharlaPAgendaDAO() {
		return charlaPAgendaDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setCharlaPAgendaDAO(ICharlaPAgendaDAOT charlaPAgendaDAO) {
		this.charlaPAgendaDAO = charlaPAgendaDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
